#include<stdio.h>
#include<string.h>

int main()
{
	int key=0,num=0,sign=0,flag=0;
	char c[100]={'\0'},z,z1;
	scanf("%c %d",&z,&key);
	scanf("%s",&c);
	if(z>='a'&&z<='z') z1=z-32;
	else z1=z+32;
	for(sign=0;sign<strlen(c);sign++)
	{
		if(key==0) 
		{
			if(c[sign]==z||c[sign]==z1) num++;
		}
		else if(c[sign]==z) num++;
	}
	printf("%d",num);
	return 0;
}
